package com.lai.lai.utils;

import com.lai.lai.enums.EmBusiness;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author lmx
 * @Date 2021/4/27 23:21
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultResponse<T>{
    private int code;
    private String msg;
    private T data;


    public static <T> ResultResponse<T> ok(T data){

        return response(EmBusiness.SUCCESS.getCode(), EmBusiness.SUCCESS.getMsg(),data);
    }
    public static <T> ResultResponse<T> ok(){
        return response(EmBusiness.SUCCESS.getCode(), EmBusiness.SUCCESS.getMsg(),null);
    }

    public static <T> ResultResponse<T> fail(){
        return response(EmBusiness.FAIL.getCode(), EmBusiness.FAIL.getMsg(), null);
    }
    public static <T> ResultResponse<T> fail(Integer code,String msg){
        return response(code, msg, null);
    }

    private static <T> ResultResponse<T> response(int code, String msg, T data) {
        return new ResultResponse<>(code, msg, data);
    }
}
